<script type="text/javascript">
    $(document).ready(function() {
        $('#no_induk').blur(function() {
            $("#nama").css("color", "black");
            $("#nama").text("");
            $("#kelas").text("");
            $("#kelamin").text("");
            $("#usia").text("");
            $("#siswa_id").val("");
            $("#submit").attr('disabled','disabled');
            if($('#no_induk').val()!=""){
                $.ajax({
                    type : 'POST',
                    url : '<?php echo url_for('iq/jsonsiswa') ?>',
                    dataType : 'json',
                    data: {
                        no_induk : $('#no_induk').val()
                    },
                    success : function(data){
                        if(data.success){
                            $("#submit").removeAttr("disabled");
                            $("#nama").text(data.nama);
                            $("#kelas").text();
                            $("#kelamin").text(data.jk);
                            $("#usia").text(data.usia+" tahun");
                            $("#siswa_id").val(data.id);
                        }else{
                            $("#nama").text('Siswa dengan No. Induk '+$('#no_induk').val()+' tidak ditemukan!');
                            $("#nama").css("color", "red");
                        }
                    }
                });
            }
        });
    });
</script>
<h1>New Iq</h1>

<form action="<?php echo url_for('iq/' . ($form->getObject()->isNew() ? 'create' : 'update') . (!$form->getObject()->isNew() ? '?id=' . $form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
    <?php echo $form->renderHiddenFields(false) ?>
    <?php if (!$form->getObject()->isNew()): ?>
        <input type="hidden" name="sf_method" value="put" />
    <?php endif; ?>
    <fieldset>
        <legend>IQ</legend>
        <table class="form">
            <tbody>
                <?php echo $form->renderGlobalErrors() ?>
                <tr>
                    <th><?php echo $form['no_induk']->renderLabel() ?></th>
                    <td><?php echo $form['no_induk']->render(array('autofocus' => 'autofocus')) ?></td>
                </tr>
                <?php if ($form['no_induk']->hasError()): ?>
                    <tr>
                        <th>&nbsp;</th>
                        <td><?php echo $form['no_induk']->renderError() ?></td>
                    </tr>
                <?php endif; ?>
                <tr>
                    <th>&nbsp;</th>
                    <td>
                        <table style="border: 1px solid #dcdcdc;width: 100%">
                            <tr>
                                <td width="70%" style="font-size: 10pt">Nama</td><td style="font-size: 10pt">Kelas</td></td><td width="1px">&nbsp;</td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold;border-bottom: 1px solid #dcdcdc"><span id="nama">&nbsp;</span></td><td style="font-weight: bold;border-bottom: 1px solid #dcdcdc"><span id="kelas">&nbsp;</span></td><td width="1px">&nbsp;</td>
                            </tr>
                            <tr>
                                <td style="font-size: 10pt">Jenis Kelamin</td><td style="font-size: 10pt">Usia</td></td><td width="1px">&nbsp;</td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold"><span id="kelamin">&nbsp;</span></td><td style="font-weight: bold"><span id="usia">&nbsp;</span></td></td><td width="1px">&nbsp;</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <th><?php echo $form['jenjang_id']->renderLabel() ?></th>
                    <td><?php echo $form['jenjang_id']->render() ?></td>
                </tr>
                <?php if ($form['jenjang_id']->hasError()): ?>
                    <tr>
                        <th>&nbsp;</th>
                        <td><?php echo $form['jenjang_id']->renderError() ?></td>
                    </tr>
                <?php endif; ?>
                <tr>
                    <th><?php echo $form['nilai']->renderLabel() ?></th>
                    <td><?php echo $form['nilai']->render(array('class' => 'pendek')) ?></td>
                </tr>
                <?php if ($form['nilai']->hasError()): ?>
                    <tr>
                        <th>&nbsp;</th>
                        <td><?php echo $form['nilai']->renderError() ?></td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </fieldset>
    <br />
    <?php if (isset($kecerdasan_list)): ?>
        <fieldset>
            <legend>Kecerdasan</legend>
            <table class="form">
                <tfoot>
                    <tr>
                        <td width="30%">&nbsp;</td>
                        <td>
                            <input type="submit" value="Simpan" class="button" id="submit" disabled="disabled" />
                            &nbsp;<a href="<?php echo url_for('iq/index') ?>">Back to list</a>
                            <?php if (!$form->getObject()->isNew()): ?>
                                &nbsp;<?php echo link_to('Delete', 'iq/delete?id=' . $form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
                            <?php endif; ?>
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <?php foreach ($kecerdasan_list as $value): ?>
                        <tr>
                            <th><?php echo $form['kecerdasan' . $value->getId()]->renderLabel() ?></th>
                            <td><?php echo $form['kecerdasan' . $value->getId()]->render() ?></td>
                        </tr>
                        <?php if ($form['kecerdasan' . $value->getId()]->hasError()): ?>
                            <tr>
                                <th>&nbsp;</th>
                                <td><?php echo $form['kecerdasan' . $value->getId()]->renderError() ?></td>
                            </tr>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </fieldset>
    <?php endif; ?>
</form>